package com.devilvan.betrice.opgg.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devilvan.betrice.opgg.dto.OpggChampionPositionDto;
import com.devilvan.betrice.opgg.po.OpggChampionPositionPo;
import com.devilvan.betrice.opgg.service.OpggChampionPositionService;
import com.devilvan.betrice.opgg.mapper.OpggChampionPositionMapper;
import com.devilvan.betrice.opgg.repository.OpggChampionPositionRepository;
import com.devilvan.betrice.util.UCopy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Evad.Wu
 * @Description OPGG-英雄位置信息 业务逻辑类
 * @date 2022-10-04
 */
@Service
public class OpggChampionPositionServiceImpl extends ServiceImpl<OpggChampionPositionMapper, OpggChampionPositionPo> implements OpggChampionPositionService {
    @Resource(name = "opggChampionPositionRepository")
    private OpggChampionPositionRepository opggChampionPositionRepository;

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public OpggChampionPositionPo saveUpdate(OpggChampionPositionDto opggChampionPositionDto) {
        OpggChampionPositionPo opggChampionPositionPo = new OpggChampionPositionPo();
        UCopy.fullCopy(opggChampionPositionDto, opggChampionPositionPo);
        return opggChampionPositionRepository.saveAndFlush(opggChampionPositionPo);
    }

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public List<OpggChampionPositionPo> saveUpdateBatch(List<OpggChampionPositionDto> list) {
        List<OpggChampionPositionPo> opggChampionPositionPoList = UCopy.fullCopyCollections(list, OpggChampionPositionPo.class);
        return opggChampionPositionRepository.saveAllAndFlush(opggChampionPositionPoList);
    }
}
